import { HtmlNode, HtmlNodeModel, GraphModel, NodeConfig } from '@logicflow/core'
import { getBpmnId } from '../getBpmnId'
import './events.scss'
class StartEventModel extends HtmlNodeModel {
  static extendKey = 'StartEventModel'
  constructor(data: NodeConfig, graphModel: GraphModel) {
    if (!data.id) {
      data.id = `startEvent_${getBpmnId()}`
    }
    if (!data.text) {
      data.text = ''
    }
    if (data.text && typeof data.text === 'string') {
      data.text = {
        value: data.text,
        x: data.x,
        y: data.y + 2,
      }
    }

    // fix: 不能直接全部加，会导致下载后再次上传，位置错误。
    // data.text.y += 40;
    super(data, graphModel)
  }
  getTextStyle() {
    const style = super.getTextStyle()
    style.color = '#fff'
    style.fontSize = 16
    return style
  }
  setAttributes(): void {
    this.width = 150
    this.height = 60
  }
}

class StartEventView extends HtmlNode {
  static extendKey = 'StartEventNode'
  setHtml(rootEl: HTMLElement) {
    const el = document.createElement('div')
    const html = `
      <div class="start-wrapper">
				
      </div>
    `
    el.innerHTML = html
    // 需要先把之前渲染的子节点清除掉。
    rootEl.innerHTML = ''
    rootEl.appendChild(el)
  }
}

const StartEvent = {
  type: 'bpmn2:startEvent',
  view: StartEventView,
  model: StartEventModel,
}

export { StartEventModel, StartEventView }
export default StartEvent
